package com.nowcoder.Offer.FlowWindow;

import org.junit.Test;

import java.util.ArrayList;

/**
 * 和为s的连续序列
 */
public class FindDesSum {

    ArrayList<ArrayList<Integer>> ans = new ArrayList<ArrayList<Integer>>();

    public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {
        if(sum == 0) return ans;
        int l = 1, r = 2;
        while(l<r){
            int curSum = (l+r)*(r-l+1)/2;
            if(curSum == sum){
                ArrayList<Integer> res = new ArrayList<>();
                for(int i=l; i<=r; i++)
                    res.add(i);
                ans.add(res);
                l++;
            }
            else if(curSum<sum) r++;
            else l++;
        }

        return ans;
    }

    @Test
    public void test(){
        FindContinuousSequence(100).forEach(System.out::println);
    }
}
